<template>
	<view class="verified">
		<view class="input-group">
			
			<view class="input-row">
				<view class="icon iconfont icon-mima"></view>
				<input type="text" :password="true"  v-model="old_password"  placeholder="请输入原密码" />
			</view>

			<view class="input-row">
				<view class="icon iconfont icon-mima"></view>
				<input type="text" :password="true"  v-model="password"  maxlength="18" placeholder="请输入新密码"/>
			</view>

			<view class="input-row">
				<view class="icon iconfont icon-mima"></view>
				<input type="text" :password="true"  v-model="confirm_password"  maxlength="18" placeholder="请重新输入新密码"/>
			</view>
			
			<view class="radius-btn" @tap="reset()">确认修改</view>

		</view>

		

	</view>
</template>

<script>
	import Request from '../../common/request.js';
	
	export default {
		data() {
			return {
				old_password: '',
				password: '',
				confirm_password: '',
				type: ''
			};
		},
		onLoad(e) {
			this.type = e.type;
		},
		methods: {
			reset:function(){

				if(!this.old_password){
					Request.alert('请输入原密码');return;
				}


				if(!this.password) {
					Request.alert('请输入新密码');
					return;
				}

				if(!this.confirm_password){
					Request.alert('请重新输入新密码');return;
				}

				if(this.confirm_password != this.password){
					Request.alert('两次密码不一致');return;
				}

	
				var payPreg = /^\d{6}$/;
				if(this.type == 'pay' && !payPreg.test(this.password)){
					Request.alert('支付密码为6位数字');return;
				}

				if(this.type == 'password') {
					var url =  'user/changePassword';
				} else {
					var url =  'user/changePayPassword';
				}
				var that = this;

				var formData = {
					
					old_password: that.old_password,
					password: that.password,
					confirm_password: that.confirm_password,
				};
				
				Request.send({
					url: url,
					data: formData,
					sCallback: function(res) {
						Request.alert(res.msg, () => {
							uni.navigateBack({
								
							})
						})
					}
				})

				

			},
		}
	}
</script>

<style>
	.verified{
		font-size: 28upx;
		margin-bottom: 90upx;
	}

	
	.input-group{
		background: #fff;
	}
	
	
	.input-row{
		display: flex;
		height: 80upx;
		padding: 0 40upx;
		align-items: center;
		border-bottom: 1upx solid #eee;
	}
	
	.input-row .icon{
		margin-right: 10upx;
	}
	
	.input-row input{
		flex: 1;
	}
	
	.radius-btn{
		margin-top: 60upx;
	}
</style>
